package cn.mrcode.smartPluginSecurity;

import org.apache.shiro.web.env.EnvironmentLoaderListener;

import javax.servlet.FilterRegistration;
import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import java.util.Set;

/**
 * @author zhuqiang
 * @version V1.0
 * @date 2015/11/16 20:04
 */
public class SmartSecurityPlugin implements ServletContainerInitializer {
    @Override
    public void onStartup(Set<Class<?>> set, ServletContext servletContext) throws ServletException {
        //设置初始化参数
        servletContext.setInitParameter("shiroConfigLocations","classpath:smart-security.ini");//覆盖掉默认的shiro配置文件名称
        servletContext.addListener(EnvironmentLoaderListener.class); //标准的shiro的启动配置项
        FilterRegistration.Dynamic smartSecurityFilter = servletContext.addFilter("SmartSecurityFilter", SmartSecurityFilter.class);
        smartSecurityFilter.addMappingForUrlPatterns(null,false,"/*"); //加载我们自己的filter。并设置拦截路径
    }
}
